package com.snails.array;

import java.util.Arrays;

public class LeetCode66 {
    public static void main(String[] args) {
        LeetCode66 leetCode66 = new LeetCode66();
        int[] digits = {9,9,9};
        System.out.println(Arrays.toString(leetCode66.plusOne(digits)));
    }

    public int[] plusOne(int[] digits) {
        int index = digits.length - 1;
        return plusOne(digits, index);
    }

    public int[] plusOne(int[] digits, int index) {
        if (index < 0) {
            int[] newDigits = new int[digits.length + 1];
            newDigits[0] = 1;
            return newDigits;
        }
        int addVal = digits[index] + 1;
        if (addVal == 10) {
            digits[index] = 0;
            return plusOne(digits, index - 1);
        } else {
            digits[index] = addVal;
            return digits;
        }
    }
}
